<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.List" %>
<%@ page import="javax.naming.*"%>
<%@ page import="org.swimv2.entities.*" %>
<%@ page import="org.swimv2.interfaces.*" %>
<%@ page import="org.swimv2.utils.ContextUtil" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
User curr_u = (User) request.getSession().getAttribute("user");
//@SuppressWarnings("unchecked")
//List<Skill> skills = (List<Skill>) request.getAttribute("skills");
Context ctx = ContextUtil.getInitialContext();
SkillManagerRemote mgr_s = (SkillManagerRemote) ctx.lookup("SkillManagerJNDI");
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
@import url(/WEBswim2/css/main.css);
</style>
<title>Admin Profile</title>
</head>
<body>

<p class="homenav"><a href="/WEBswim2/home.jsp"><span>Home</span></a></p>
<% if (curr_u != null) { %>
<ul class="ul_nav">
    <li><a href="/WEBswim2/Logout">Logout</a></li>
    <li><a href="/WEBswim2/user/profile.jsp">Il Mio Profilo</a> <em>[<% out.print(curr_u.getFirstName() +" "+ curr_u.getLastName()); %>]</em></li>
</ul>
<% } %>

<h1>Pannello di controllo Amministratore</h1>
<%
    String msg = (String) request.getAttribute("message");
    if (msg != null) {
        out.println("<p class=\"message\">"+ msg +"</p>");
    }
    String err = (String) request.getAttribute("error_message");
    if (err != null) {
        out.println("<p class=\"error_message\">"+ err +"</p>");
    }
%>

<%
/* Pagina visibile solo agli amministratori */
if (curr_u != null && curr_u.getIsAdmin()) { 
%>

<h3>Modifica lista competenze attive:</h3>
<em><strong>Nota:</strong> non &egrave; possibile rimuovere competenze gi&agrave; in uso.</em>
<%
    if (mgr_s.listAllActiveSkills() != null) {
    	%><ul><%
	    for (Skill s : mgr_s.listAllActiveSkills()) {
	    	out.println("<li>"+ s.getName()
	    			   +" (<a href='/WEBswim2/EvalSkillReqs?how=removeactive&s_id="
	    			   + s.getId() +"'>Rimuovi</a>)</li>");
	    }
    	%></ul><%
    }
    else { %><p><em>Nessuna competenza attiva.</em></p><% }
%>

<h3>Valuta richieste di aggiunta competenze:</h3>
<em>La lista di richieste inviate dagli utenti registrati</em>
<%
    if (mgr_s.listAllSkillReq() != null) {
    	%><ul><%
	    for (Skill s : mgr_s.listAllSkillReq()) {
	        out.println("<li>"+ s.getName()
		        		+ " (<a href='/WEBswim2/EvalSkillReqs?how=accept&s_id="
		                + s.getId() +"'>Accetta</a>)"
		                + " (<a href='/WEBswim2/EvalSkillReqs?how=reject&s_id="
		                + s.getId() +"'>Rifiuta</a>)</li>");
	    }
	    %></ul><%
    }
    else { %><p><em>Nessuna richiesta da valutare.</em></p><% }
%>

<h3>Aggiungi nuove competenze:</h3>
<form action="/WEBswim2/EvalSkillReqs" method="post">
  <fieldset>
    <input type="hidden" name="how" value="addnew" />
    <label for="name">Inserisci nome della nuova competenza:</label><br/>
    <input type="text" name="name"/>
    <input type="submit" name="submit" value="Aggiungi"/>
  </fieldset>
</form>

<% } %>

</body>
</html>